package yf.mall.dao;

import com.yf.dao.BaseDao;
import org.apache.ibatis.annotations.Select;
import yf.mall.entity.MallGoodsEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import yf.mall.vo.web.MallGoodsVO;
import yf.mall.vo.down.AccountDown;
import yf.mall.vo.down.ProfitDown;
import yf.mall.vo.down.StoreDown;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 产品Dao
 *
 *
 *
 * @date Mon Aug 05 11:30:53 CST 2019
 */
@Mapper
public interface MallGoodsDao extends BaseDao<MallGoodsEntity> {

    /**api**/

    /**
     * back
     **/
    void increaseStock(@Param("goodsId") Long goodsId, @Param("quantity") Integer quantity);

    void decreaseStock(@Param("goodsId") Long goodsId, @Param("quantity") Integer quantity);

    void increaseSkuStock(@Param("goodsId") Long goodsId, @Param("skuName") String skuName, @Param("quantity") Integer quantity);

    void decreaseSkuStock(@Param("goodsId") Long goodsId, @Param("skuName") String skuName, @Param("quantity") Integer quantity);

    List<MallGoodsEntity> findBySaleType(Map<String,Object> map);

    List<MallGoodsEntity> findBySaleTypeId(Long saleTypeId);

    List<MallGoodsEntity> queryMallGoods(Map<String,Object> map);

    List<MallGoodsEntity> searchName(@Param("name") String name,@Param("shelf") int shelf);

    List<MallGoodsEntity> findGoods(int shelf);

    List<MallGoodsEntity> findByUserId(@Param("userId") Long userId,@Param("shelf")Integer shelf);

    List<MallGoodsEntity> findByTypeAndGoodsNameAndShelf(@Param("type") Integer type,@Param("name") String name,@Param("shelf")Integer shelf,@Param("userId")Long userId,@Param("saleType")Integer saleType);

    List<MallGoodsEntity> findNoGoodId(Long id);

    List<MallGoodsEntity> findUserIdIsNull(@Param("shelf") Integer shelf);

    void delByUserId(Long userId);

    void untieAct(@Param("id")Long id,@Param("shelf")Integer shelf);

    List<MallGoodsEntity> findDailyList(Integer shelf, Integer dailySel,Integer dailySelRotation);

    List<MallGoodsEntity> findByDaily(Integer shelf, Integer dailySel);

    List<ProfitDown> downProfit(@Param("start") Date start, @Param("end") Date end);

    List<AccountDown> downAccount();

    List<StoreDown> downStore();

    List<MallGoodsEntity> findByHome(Integer saleType, Integer shelf);

    /**
     * 上架的品牌代理
     * @return
     */
    @Select("select id,img,now_price,old_price from mall_goods where shelf = 1 and sale_type = 0 order by sort")
    List<MallGoodsEntity> findHomeGoods();

    @Select("select id,name,weight,mid_img,big_img,now_price,stock,total_stock,unit,create_time,guaranty,level_name from mall_goods where shelf = 1 and id = #{id}")
    MallGoodsVO findGoodsById(Long id);

    List<MallGoodsVO> findByTypeAndName(String goodsName, Integer type, Integer page, Integer limit);
}
